package com.tianlu.store.common;

import com.github.pagehelper.PageInfo;
import java.util.List;

public class PageResult<T> {
    private List<T> list;
    private Long totalCount;
    private Integer totalPage;
    private Integer page;

    public static PageResult resultPage(PageInfo<?> pageInfo) {
        return builder().page(pageInfo.getPageNum()).totalPage(pageInfo.getPages()).list((List<Object>) pageInfo.getList()).totalCount(pageInfo.getTotal()).build();
    }

    public static <T> PageResultBuilder<T> builder() {
        return new PageResultBuilder();
    }

    public List<T> getList() {
        return this.list;
    }

    public Long getTotalCount() {
        return this.totalCount;
    }

    public Integer getTotalPage() {
        return this.totalPage;
    }

    public Integer getPage() {
        return this.page;
    }

    public void setList(final List<T> list) {
        this.list = list;
    }

    public void setTotalCount(final Long totalCount) {
        this.totalCount = totalCount;
    }

    public void setTotalPage(final Integer totalPage) {
        this.totalPage = totalPage;
    }

    public void setPage(final Integer page) {
        this.page = page;
    }

    public PageResult(final List<T> list, final Long totalCount, final Integer totalPage, final Integer page) {
        this.list = list;
        this.totalCount = totalCount;
        this.totalPage = totalPage;
        this.page = page;
    }

    public static class PageResultBuilder<T> {
        private List<T> list;
        private Long totalCount;
        private Integer totalPage;
        private Integer page;

        PageResultBuilder() {
        }

        public PageResultBuilder<T> list(final List<T> list) {
            this.list = list;
            return this;
        }

        public PageResultBuilder<T> totalCount(final Long totalCount) {
            this.totalCount = totalCount;
            return this;
        }

        public PageResultBuilder<T> totalPage(final Integer totalPage) {
            this.totalPage = totalPage;
            return this;
        }

        public PageResultBuilder<T> page(final Integer page) {
            this.page = page;
            return this;
        }

        public PageResult<T> build() {
            return new PageResult(this.list, this.totalCount, this.totalPage, this.page);
        }

        public String toString() {
            return "PageResult.PageResultBuilder(list=" + this.list + ", totalCount=" + this.totalCount + ", totalPage=" + this.totalPage + ", page=" + this.page + ")";
        }
    }
}

